<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item label="培养单位">
              <a-select allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="专业">
              <a-select allowClear v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
            <a-form-item label="年级">
              <a-select allowClear v-model="queryParam.sznj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="refreshTable" style="margin:0 10px">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <div style="text-align:center; font-size: 15px;margin-bottom: 20px;">硕士研究生中期考核统计结果 <a-button type="primary" style="float: right;" @click="exportExcel(431)">导出</a-button></div>
      <s-table
        v-if="init"
        ref="table1"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData1"
        :alert="{show: true}"
        :scroll="{ x: 1400 }"
        :pageSize="parameter1.pageSize"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter1.pageNo - 1) * parameter1.pageSize }}
        </span>
      </s-table>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <div style="text-align:center; font-size: 15px;margin-bottom: 20px;">博士研究生中期考核统计结果 <a-button type="primary" style="float: right;" @click="exportExcel(432)">导出</a-button></div>
      <s-table
        v-if="init"
        ref="table2"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData2"
        :alert="{show: false}"
        :scroll="{ x: 1400 }"
        :pageSize="parameter2.pageSize"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 + (parameter2.pageNo - 1) * parameter2.pageSize }}
        </span>
      </s-table>
    </a-card>
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'

export default {
  data () {
    return {
      advanced: true,
      queryParam: {},
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '院系名',
          dataIndex: 'ssyxmc'
        },
        {
          title: '专业名',
          dataIndex: 'sszymc'
        },
        {
          title: '年级',
          dataIndex: 'sznj'
        },
        {
          title: '优秀',
          dataIndex: 'yx'
        },
        {
          title: '合格',
          dataIndex: 'hg'
        },
        {
          title: '基本合格',
          dataIndex: 'jbhg'
        },
        {
          title: '不合格',
          dataIndex: 'bhg'
        },
        {
          title: '培养办未审核或审核未通过',
          dataIndex: 'yxwshhshwtg'
        },
        {
          title: '未参加中期考核',
          dataIndex: 'wcjzqkh'
        },
        {
          title: '总人数',
          dataIndex: 'zrs'
        }
      ],
      parameter1: {
        pageNo: 1,
        pageSize: 10
      },
      parameter2: {
        pageNo: 1,
        pageSize: 10
      },
      loadData1: parameter => {
        this.parameter1 = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign({xslb: 431}, this.queryParam, parameter)
        return this.$api.cultivate.midTermStatis(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      loadData2: parameter => {
        this.parameter2 = parameter
        parameter.pageNum = parameter.pageNo
        let params = Object.assign({xslb: 432}, this.queryParam, parameter)
        return this.$api.cultivate.midTermStatis(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {},
      init: false
    }
  },
  components: {STable},
  computed: {
    ...mapState({
      TYPE0109: state => state.app['TYPE0109'],
      TYPE0126: state => state.app['TYPE0126']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0109')
    this.$store.dispatch('app/setDictionary', 'TYPE0126')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll(),
        this.$store.dispatch('app/sysInfo')
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
        this.$set(this.queryParam, 'sznj', res[1].currentGrade)
        this.init = true
      })
    },
    refreshTable () {
      this.$refs.table1.refresh(true)
      this.$refs.table2.refresh(true)
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    exportExcel (xslb) {
      let params = {...this.queryParam, xslb}
      delete params.pageNum
      this.$export('/foster/zqkhxx/zqkhtjExp', params)
    }
  }
}
</script>

<style>

</style>
